#include "Parser.h"
#include "List.h"

function listDemo();
function betterListDemo();
function stringListTesting();

function main(int argc, char* argv[])
{
    //listDemo();
    //betterListDemo();
    //stringListTesting();

    initParser("TestSemantic.txt");
    simpleAllStars();

    mark("\n\nSymTab: \n*******\n", 0);
    printSymTabStack();
    clearParser();
}

function stringListTesting()
{
    char ptr s1 = "Walter";
    char ptr s2 = "Peter";
    char ptr s3 = "Hans";
    char ptr s4 = "Markus";
    addString(s1);
    addString(s2);
    addString(s3);
    addString(s4);
    printStringList();

    while(hasNextString() == 1)
    {
        printf("String: %s\n", getNextString());
    }

    clearStringList();

    addString(s1);
    addString(s2);
    addString(s3);
    addString(s4);
    while(hasNextString() == 1)
    {
        printf("String: %s\n", getNextString());
    }

    printStringList();
}

function betterListDemo()
{
    initSymTabStack();

    struct SymTab ptr symTab = newSymTab;
    push(symTab);
    initSubSymTab(symTab);

    struct Type ptr type = newType;
    type-> form = 666;
    type-> len = 999;
    type-> fields = NULL;
    type-> base = NULL;

    struct Object ptr obj1 = newObject;
    struct Object ptr obj2 = newObject;
    struct Object ptr obj3 = newObject;

    obj1-> name = "Hallo1";
    obj2-> name = "Hallo2";
    obj3-> name = "Hallo3";
    obj1-> oClass = 1;
    obj2-> oClass = 1;
    obj3-> oClass = 1;
    obj1-> type = type;
    obj2-> type = type;
    obj3-> type = type;
    obj1-> val = 1;
    obj2-> val = 1;
    obj3-> val = 1;

    addObj(symTab, obj1);
    addObj(symTab, obj2);
    addObj(symTab, obj3);

    printf("\n\n");
    printSymTabStack();

    printf("\n\n");
    printf("Object found?\n");
    struct Object ptr object;
    object = search("NULL");
    if(object neq NULL)
    {
        printf("o: \n");
        printObj(object);
    }

    pop();

    printf("\n\n");
    printSymTabStack();
}

function listDemo()
{
    struct SymTab ptr symTab = newSymTab;
    initSymTab(symTab);

    struct Type ptr type = newType;
    type-> form = 666;
    type-> len = 999;
    type-> fields = NULL;
    type-> base = NULL;

    add(symTab, "Hallo", 0, type, 3);
    add(symTab, "Hallo2", 0, type, 4);
    add(symTab, "Hallo3", 0, type, 4);

    deleteByName(symTab, "NULL");
    deleteByName(symTab, "Hallo");
    deleteByName(symTab, "Hallo2");
    deleteByName(symTab, "Hallo3");
    deleteList(symTab);




    struct SymTab ptr symTab2 = newSymTab;
    initSymTab(symTab2);
    add(symTab2, "Hallo", 0, type, 3);
    add(symTab2, "Hallo2", 0, type, 4);
    add(symTab2, "Hallo3", 0, type, 4);

    printf("SymTab: \n");
    //printSymTable(symTab2);

    struct Object ptr object;
    object = getByName(symTab2, "Hallo");
    if(object neq NULL)
    {
        printf("o: \n");
        printObj(object);
    }

    //printSymTable(symTab2);
    deleteList(symTab2);

    struct SymTab ptr symTab3 = newSymTab;
    initSymTab(symTab3);

    struct Type ptr type2 = newType;
    type2-> form = 666;
    type2-> len = 999;
    type2-> fields = NULL;
    type2-> base = NULL;

    int length = 10;
    char ptr structIdent = (char ptr) malloc(length * (sizeof(char)));
    int i;
    for(i = 0; i < length; i++)
    {
        structIdent[i] = 'a';//curKey.value[i];
    }

    char ptr structIdent2 = (char ptr) malloc(length * (sizeof(char)));
    int j;
    for(j = 0; j < length; j++)
    {
        structIdent2[j] = 'a';//curKey.value[i];
    }
    add(symTab3, structIdent, 0, type2, 3);
    add(symTab3, structIdent2, 0, type2, 3);

    printSymTable(symTab3);
}

void printCharVal()
{
    printf("a: %d\n", 'a');
    printf("z: %d\n\n", 'z');
    printf("A: %d\n", 'A');
    printf("Z: %d\n\n", 'Z');
    printf("0: %d\n", '0');
    printf("9: %d\n\n", '9');
    printf("' ': %d\n", ' ');
    printf("'   ': %d\n", ' ');
    printf("'\\n': %d\n", '\n');

}
